﻿namespace EOrm.NpgsqlProvider
{
    /// <summary>
    /// 变量映射
    /// </summary>
    public class VariableTypeMapper : IVariableTypeMapper
    {
        /// <summary>
        /// 变量名映射方法
        /// </summary>
        /// <param name="variableTypeName">变量类型名</param>
        /// <returns>pg数据库变量类型映射</returns>
        /// <exception cref="ArgumentException">参数异常</exception>
        public string VariableTypeMap(string variableTypeName)
        {
            switch (variableTypeName.ToLower())
            {
                case "int16":
                case "uint16":
                case "samllint":
                    return "samllint";
                case "int32":
                case "uint32":
                case "integer":
                    return "integer";
                case "int64":
                case "uint64":
                case "bigint":
                    return "bigint";
                case "single":
                case "real":
                    return "real";
                case "double":
                    return "double";
                case "datetime":
                case "timestamp without timezone":
                    return "timestamp without timezone";
                case "boolean":
                case "bool":
                    return "boolean";
                case "decimal":
                    return "numeric";
                case "char":
                case "string":
                case "varchar":
                    return "varchar";
                default:
                    throw new ArgumentException(string.Format("变量类型{0}在postgres数据库中没有可映射的类型", variableTypeName));
            }
        }

        /*
         * switch (propertyInfoName.ToLower())
                    {
                        case "int16":
                        case "uint16":
                        case "int32":
                        case "uint32":
                            return "integer";
                        case "int64":
                        case "uint64":
                            return "bigint";
                        case "single":
                        case "double":
                            return "real";
                        case "datetime":
                            return "datetime";
                        case "boolean":
                        case "bool":
                            return "boolean";
                        case "char":
                        case "string":
                            return "text";
                        default:
                            throw new ArgumentException(string.Format("数据库{0}不支持{1}", dbStyle, propertyInfoName));
         */
    }
}
